import type { ICourse } from "@/utils/types";
import type { ProColumns } from "@ant-design/pro-components";
import { Button, Space } from "antd";

interface IProps {
  onEditHandler: (id: string) => void;
  onCardHandler: (id: string) => void;
  onOrderTimeHandler: (id: string) => void;
}

export const getColumns: ({
  onEditHandler,
  onCardHandler,
  onOrderTimeHandler,
}: IProps) => ProColumns<ICourse, "text">[] = ({
  onEditHandler,
  onCardHandler,
  onOrderTimeHandler,
}) => {
  return [
    {
      title: "课程标题",
      dataIndex: "name",
      // key: "name",
      ellipsis: true,
      copyable: true,
    },
    {
      title: "限制人数",
      dataIndex: "limitNumber",
      // key: "limitNumber",
      width: 75,
      search: false, //关闭搜索
    },
    {
      title: "持续时长",
      dataIndex: "duration",
      key: "duration",
      width: 75,
      search: false,
    },
    {
      title: "操作",
      dataIndex: "id",
      key: "id",
      valueType: "option",
      align: "center",
      width: 300,
      render: (_text, entity) => (
        <Space>
          <Button
            key="edit"
            type="link"
            onClick={() => onEditHandler(entity.id)}
          >
            编辑
          </Button>
          <Button
            key="orderTime"
            type="link"
            onClick={() => onOrderTimeHandler(entity.id)}
          >
            可约时间
          </Button>
          <Button
            key="card"
            type="link"
            onClick={() => onCardHandler(entity.id)}
          >
            关联消费卡
          </Button>
        </Space>
      ),
    },
  ];
};
